package com.dao.qsl;

import com.bean.qsl.BxInfo;
import com.util.qsl.Dbutil;
import org.springframework.stereotype.Repository;

import javax.servlet.http.HttpServletRequest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class Sqbx {
      public  List<BxInfo> bx(HttpServletRequest request){
            Dbutil d=new Dbutil();
            Connection c=null;

            List<BxInfo> list=new ArrayList<>();

            Map<String,Object> user = (Map<String,Object>)request.getSession().getAttribute("user");
            String ename = (String) user.get("Hname");
//            String aid = (String) user.get("aid");
//            System.out.println("用户名:"+ename);
//            System.out.println("用户名id:"+aid);
            try {
                  c=d.getConnection();
                  String sql="SELECT m.*,h.hname from household h, maintain m where m.aid=h.aid  and  h.hname=? ";

                  PreparedStatement pr=c.prepareStatement(sql);

                  pr.setString(1,ename);

                  ResultSet rs=pr.executeQuery();

                  while (rs.next()) {
                        BxInfo b=new BxInfo();
                        b.setDdxh(rs.getInt("maintain_id"));
                        b.setZhxm(rs.getString("hname"));
                        b.setBxlr(rs.getString("maintain_content"));
                        b.setTbxq(rs.getString("tpdz"));
                        b.setSqrq(rs.getString("maintain_date"));
                        b.setLxdh(rs.getString("maintain_phone"));
                        b.setClzt(rs.getString("maintain_status"));
                        b.setPf(rs.getString("maintain_appraise"));
                        list.add(b);
                  }


            }catch (Exception e) {
                  e.printStackTrace();
            }

            return list;
      }
}
